package com.marchsoft.controller;

import com.marchsoft.common.advice.CommonExceptionHandler;
import com.marchsoft.domain.Student;
import com.marchsoft.service.IActivityService;
import com.marchsoft.vo.UnDoMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * class description：
 * author：rsw
 * Date: 2019/11/17
 * Time: 10:49
 **/
@RestController
@RequestMapping("activity")
public class ActivityController extends CommonExceptionHandler {

    @Autowired
    private IActivityService activityService;

    /**
     * 导师处理学生的申请
     *
     * @param sid    学生id
     * @param tid    导师id
     * @param status 2为同意、3为拒绝
     * @return boolean
     */
    @RequestMapping("/applying/teacher")
    public ResponseEntity<Boolean> insertApplyingTeacher(Integer sid, Integer tid, Integer status) {
        return ResponseEntity.ok(activityService.insertApplyingTeacher(sid, tid, status));
    }

    /**
     * 兴趣小组处理学生的申请
     *
     * @param sid    学生id
     * @param gid    导师id
     * @param status 2为同意、3为拒绝
     * @return boolean
     */
    @RequestMapping("/applying/group")
    public ResponseEntity<Boolean> insertApplyingGroup(Integer sid, Integer gid, Integer status) {
        return ResponseEntity.ok(activityService.insertApplyingGroup(sid, gid, status));
    }

    /**
     * 查询已处理和未处理的信息
     *
     * @param tid  老师id
     * @param type 0是已处理;1是未处理
     * @return
     */
    @RequestMapping("/query/undomsg")
    public List<UnDoMsg> queryUnDoMsg(Integer tid, Integer type) {
        return activityService.queryUnDoMsg(tid, type);
    }

    /**
     * 发送退导师请求
     *
     * @param sid 学生id
     * @return
     */
    @RequestMapping(value = "/applying/outteacher", method = RequestMethod.POST)
    public int quitTeacher(
            @RequestParam(name = "sid", required = true) Integer sid) {
        return activityService.quitTeacher(sid);
    }

    /**
     * 处理 导师退出申请
     *
     * @param sid   学生id
     * @param statu 处理状态
     * @return
     */
    @RequestMapping(value = "/handle/quitteacher", method = RequestMethod.POST)
    public int handleQuitTeacher(
            @RequestParam(name = "sid", required = true) Integer sid,
            @RequestParam(name = "statu", required = true) Integer statu) {
        System.out.println("触发");
        return activityService.handleQuitTeacher(sid, statu);
    }


}

